package genedit.model;

import java.util.Set;

/**
 * Klasa zadužena za čuvanje referenci na selektovane elemente hijerarhije.
 * 
 * @author Nikola
 * @version 1.0 18/12/13
 */
public class HierarchySelection {
	/**
	 * Set selektovanih elemenata hijerarhije
	 */
	private Set<HierarchyElement> selectedHierarchyElements;

	public HierarchySelection() {
	}

	public Set<HierarchyElement> getSelectedHierarchyElements() {
		if (selectedHierarchyElements == null)
			selectedHierarchyElements = new java.util.HashSet<HierarchyElement>();
		return selectedHierarchyElements;
	}

	public java.util.Iterator<HierarchyElement> getIteratorSelectedHierarchyElements() {
		if (selectedHierarchyElements == null)
			selectedHierarchyElements = new java.util.HashSet<HierarchyElement>();
		return selectedHierarchyElements.iterator();
	}

	public void setSelectedHierarchyElements(
			java.util.Collection<HierarchyElement> newSelectedHierarchyElements) {
		removeAllSelectedHierarchyElements();
		for (java.util.Iterator<HierarchyElement> iter = newSelectedHierarchyElements.iterator(); iter
				.hasNext();)
			addSelectedHierarchyElements((HierarchyElement) iter.next());
	}

	public void addSelectedHierarchyElements(HierarchyElement newHierarchyElement) {
		if (newHierarchyElement == null)
			return;
		if (this.selectedHierarchyElements == null)
			this.selectedHierarchyElements = new java.util.HashSet<HierarchyElement>();
		if (!this.selectedHierarchyElements.contains(newHierarchyElement))
			this.selectedHierarchyElements.add(newHierarchyElement);
	}

	public void removeSelectedHierarchyElements(HierarchyElement oldHierarchyElement) {
		if (oldHierarchyElement == null)
			return;
		if (this.selectedHierarchyElements != null)
			if (this.selectedHierarchyElements.contains(oldHierarchyElement))
				this.selectedHierarchyElements.remove(oldHierarchyElement);
	}

	public void removeAllSelectedHierarchyElements() {
		if (selectedHierarchyElements != null)
			selectedHierarchyElements.clear();
	}

}